package ch.zbw.pra.sysventory.domain.visualisation;

import java.util.ArrayList;
import java.util.List;

import ch.zbw.pra.sysventory.domain.model.Software;

public class VisuControllSoftware extends AVisuControll implements IVisuControll<Software> {

	private boolean softwareName;
	private boolean softwareVendor;
	private boolean softwareVersion;

	public VisuControllSoftware() {
		super();
	}

	public boolean isSoftwareName() {
		return this.softwareName;
	}

	public void setSoftwareName(boolean softwareName) {
		this.softwareName = softwareName;
		updateObserver();
	}

	public boolean isSoftwareVendor() {
		return this.softwareVendor;
	}

	public void setSoftwareVendor(boolean softwareVendor) {
		this.softwareVendor = softwareVendor;
		updateObserver();
	}

	public boolean isSoftwareVersion() {
		return this.softwareVersion;
	}

	public void setSoftwareVersion(boolean softwareVersion) {
		this.softwareVersion = softwareVersion;
		updateObserver();
	}

	public void addDataToRow(List<Software> data, List<List<String>> row) {
		if (isSoftwareName()) {
			row.add(makeSoftwareNameList(data));
		}
		if (isSoftwareVendor()) {
			row.add(makeSoftwareVendorList(data));
		}
		if (isSoftwareVersion()) {
			row.add(makeSoftwareVersionList(data));
		}
	}

	public void addDataToColumn(List<String> data) {
		if (isSoftwareName()) {
			data.add("Software Name");
		}
		if (isSoftwareVendor()) {
			data.add("Software Hersteller");
		}
		if (isSoftwareVersion()) {
			data.add("Software Version");
		}
	}

	private List<String> makeSoftwareNameList(List<Software> software) {
		List<String> data = new ArrayList<String>();
		for (Software sw : software) {
			data.add(sw.getNameSoftware());
		}
		return data;
	}

	private List<String> makeSoftwareVersionList(List<Software> software) {
		List<String> data = new ArrayList<String>();
		for (Software sw : software) {
			data.add(sw.getVersionSoftware());
		}
		return data;
	}

	private List<String> makeSoftwareVendorList(List<Software> software) {
		List<String> data = new ArrayList<String>();
		for (Software sw : software) {
			data.add(sw.getVendor().getNameVendorSoftware());
		}
		return data;
	}

	public void restoreTo(boolean value) {
		this.softwareName = value;
		this.softwareVendor = value;
		this.softwareVersion = value;
	}

}
